/*   1:    */ package com.atomikos.icatch.imp;
/*   2:    */ 
/*   3:    */ import com.atomikos.icatch.HeurCommitException;
/*   4:    */ import com.atomikos.icatch.HeurHazardException;
/*   5:    */ import com.atomikos.icatch.HeurMixedException;
/*   6:    */ import com.atomikos.icatch.HeurRollbackException;
/*   7:    */ import com.atomikos.icatch.HeuristicMessage;
/*   8:    */ import com.atomikos.icatch.Participant;
/*   9:    */ import com.atomikos.icatch.RecoveryCoordinator;
/*  10:    */ import com.atomikos.icatch.RollbackException;
/*  11:    */ import com.atomikos.icatch.SysException;
/*  12:    */ import com.atomikos.icatch.TxState;
/*  13:    */ import java.util.Enumeration;
/*  14:    */ import java.util.Hashtable;
/*  15:    */ import java.util.Vector;
/*  16:    */ 
/*  17:    */ class IndoubtStateHandler
/*  18:    */   extends CoordinatorStateHandler
/*  19:    */ {
/*  20:    */   private int inquiries_;
/*  21:    */   private boolean recovered_;
/*  22:    */   
/*  23:    */   IndoubtStateHandler(CoordinatorImp coordinator)
/*  24:    */   {
/*  25: 62 */     super(coordinator);
/*  26: 63 */     this.inquiries_ = 0;
/*  27: 64 */     this.recovered_ = false;
/*  28:    */   }
/*  29:    */   
/*  30:    */   IndoubtStateHandler(CoordinatorStateHandler previous)
/*  31:    */   {
/*  32: 69 */     super(previous);
/*  33: 70 */     this.inquiries_ = 0;
/*  34: 71 */     this.recovered_ = false;
/*  35:    */   }
/*  36:    */   
/*  37:    */   protected void recover(CoordinatorImp coordinator)
/*  38:    */   {
/*  39: 76 */     super.recover(coordinator);
/*  40: 78 */     if (getCoordinator().getState().equals(TxState.COMMITTING))
/*  41:    */     {
/*  42: 83 */       Enumeration enumm = getCoordinator().getParticipants().elements();
/*  43: 84 */       Hashtable hazards = new Hashtable();
/*  44: 85 */       while (enumm.hasMoreElements())
/*  45:    */       {
/*  46: 86 */         Participant p = (Participant)enumm.nextElement();
/*  47: 87 */         if (!getReadOnlyTable().containsKey(p))
/*  48:    */         {
/*  49: 88 */           addToHeuristicMap(p, TxState.HEUR_HAZARD);
/*  50: 89 */           hazards.put(p, TxState.HEUR_HAZARD);
/*  51:    */         }
/*  52:    */       }
/*  53: 92 */       HeurHazardStateHandler hazardStateHandler = new HeurHazardStateHandler(this, hazards);
/*  54:    */       
/*  55:    */ 
/*  56:    */ 
/*  57:    */ 
/*  58: 97 */       getCoordinator().setStateHandler(hazardStateHandler);
/*  59:    */       
/*  60:    */ 
/*  61:100 */       hazardStateHandler.recover(coordinator);
/*  62:    */     }
/*  63:104 */     this.recovered_ = true;
/*  64:    */   }
/*  65:    */   
/*  66:    */   protected Object getState()
/*  67:    */   {
/*  68:109 */     return TxState.IN_DOUBT;
/*  69:    */   }
/*  70:    */   
/*  71:    */   protected void onTimeout()
/*  72:    */   {
/*  73:119 */     if (!getCoordinator().getState().equals(getState())) {
/*  74:120 */       return;
/*  75:    */     }
/*  76:    */     try
/*  77:    */     {
/*  78:124 */       if (this.inquiries_ < getCoordinator().getMaxIndoubtTicks())
/*  79:    */       {
/*  80:126 */         this.inquiries_ += 1;
/*  81:127 */         if (this.inquiries_ >= getCoordinator().getMaxIndoubtTicks() / 2L) {
/*  82:134 */           if (getCoordinator().getSuperiorRecoveryCoordinator() != null)
/*  83:    */           {
/*  84:135 */             printMsg("Requesting replayCompletion on behalf of coordinator " + getCoordinator().getCoordinatorId(), 2);
/*  85:    */             
/*  86:    */ 
/*  87:    */ 
/*  88:    */ 
/*  89:140 */             getCoordinator().getSuperiorRecoveryCoordinator().replayCompletion(getCoordinator());
/*  90:    */           }
/*  91:    */         }
/*  92:    */       }
/*  93:145 */       else if (getCoordinator().getSuperiorRecoveryCoordinator() == null)
/*  94:    */       {
/*  95:155 */         rollback(true, !this.recovered_);
/*  96:    */       }
/*  97:158 */       else if (getCoordinator().prefersHeuristicCommit())
/*  98:    */       {
/*  99:159 */         commit(true, false);
/* 100:    */       }
/* 101:    */       else
/* 102:    */       {
/* 103:161 */         rollback(true, true);
/* 104:    */       }
/* 105:    */     }
/* 106:    */     catch (Exception e)
/* 107:    */     {
/* 108:164 */       printMsg("Error in timeout of INDOUBT state: " + e.getMessage());
/* 109:    */     }
/* 110:    */   }
/* 111:    */   
/* 112:    */   protected void setGlobalSiblingCount(int count) {}
/* 113:    */   
/* 114:    */   protected int prepare()
/* 115:    */     throws RollbackException, IllegalStateException, HeurHazardException, HeurMixedException, SysException
/* 116:    */   {
/* 117:184 */     return 1;
/* 118:    */   }
/* 119:    */   
/* 120:    */   protected HeuristicMessage[] commit(boolean onePhase)
/* 121:    */     throws HeurRollbackException, HeurMixedException, HeurHazardException, IllegalStateException, RollbackException, SysException
/* 122:    */   {
/* 123:193 */     return commit(false, false);
/* 124:    */   }
/* 125:    */   
/* 126:    */   protected HeuristicMessage[] rollback()
/* 127:    */     throws HeurCommitException, HeurMixedException, SysException, HeurHazardException, IllegalStateException
/* 128:    */   {
/* 129:202 */     return rollback(true, false);
/* 130:    */   }
/* 131:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions\3.7.0\transactions-3.7.0.jar
 * Qualified Name:     com.atomikos.icatch.imp.IndoubtStateHandler
 * JD-Core Version:    0.7.0.1
 */